package com.zendaimoney.test.simulation.action.allinpay;

import com.zendaimoney.test.simulation.action.BaseAction;
import com.zendaimoney.test.simulation.annotation.RequestCategory;
import com.zendaimoney.test.simulation.dto.request.allinpay.quick.query.QuickCollectQueryReq;
import com.zendaimoney.test.simulation.dto.response.allinpay.quick.query.QuickCollectQueryResp;
import com.zendaimoney.test.simulation.dto.response.allinpay.quick.query.QuickCollectQueryRespBody;
import com.zendaimoney.test.simulation.dto.response.allinpay.quick.query.QuickCollectQueryRespHeader;
import com.zendaimoney.test.simulation.enums.PlatformRespCode;
import com.zendaimoney.test.simulation.enums.ThirdType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@RequestCategory(thirdType = ThirdType.ALLINPAY, bizType = "200004")
@Component(("com.zendaimoney.test.simulation.action.allinpay.QuickCollectQueryAction"))
@Slf4j
public class QuickCollectQueryAction extends BaseAction {

    @Override
    public String process(String requestInfo) {
        log.info("通联快捷支付代收查询接口");
        QuickCollectQueryReq request = new QuickCollectQueryReq();
        request = (QuickCollectQueryReq) parseMessage(request, requestInfo);
        log.info("request:{}", request.toString());

        QuickCollectQueryResp response = new QuickCollectQueryResp();

        // header
        QuickCollectQueryRespHeader header = new QuickCollectQueryRespHeader();
        header.setBatchid(request.getHeader().getReqSn());
        header.setRetCode(PlatformRespCode.AllinPay.SUCCESS.getHeadCode());
        header.setErrMsg(PlatformRespCode.AllinPay.SUCCESS.getHeadMsg());

        // body
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        QuickCollectQueryRespBody body = new QuickCollectQueryRespBody();
        body.setRetCode(PlatformRespCode.AllinPay.SUCCESS.getBodyCode());
        body.setErrMsg(PlatformRespCode.AllinPay.SUCCESS.getBodyMsg());
        body.setSettday(format.format(new Date()));

        response.setHeader(header);
        response.setBody(body);

        // 签名
        // AllinpayUtil.signMsg(response.encode(), "", "");

        return response.encode();
    }

}
